/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package builder;

import builderProduct.AbstractBuilder;
import builderProduct.FileProduct;
import cbaServer.FileHandler;
import concreteBuilders.BinaryFileBuilder;
import concreteBuilders.TextFileBuilder;
import concreteBuilders.XMLFileBuilder;
import java.util.Vector;
import operacoes2.Operacao;

/**
 *
 * @author Rente
 */
public class BuilderDirector {
    private AbstractBuilder ab;
    private FileHandler handler = FileHandler.getInstance();


    public void setAbstractBuilder(AbstractBuilder ab, Vector<Operacao> vector){
        this.ab = ab;
        ab.setVal(vector);
       
    }

    public FileProduct getFileProduct(){
        return this.ab.getFileProduct();
    }

    public void constructFile() {
		ab.createNewFileBuilderProduct();
		ab.buildCabecalho();
                ab.buildCorpo();
                ab.buildExtensao();
	}

    public void writeFiles(Vector<Operacao> vector){

        setAbstractBuilder(new BinaryFileBuilder(), vector);
        constructFile();
        getHandler().saveFileProduct(getFileProduct(), vector);

        setAbstractBuilder(new XMLFileBuilder(), vector);
        constructFile();
        getHandler().saveFileProduct(getFileProduct(), vector);

        setAbstractBuilder(new TextFileBuilder(), vector);
        constructFile();
        getHandler().saveFileProduct(getFileProduct(), vector);


    }

    /**
     * @return the handler
     */
    public FileHandler getHandler() {
        return handler;
    }

    /**
     * @param handler the handler to set
     */
    public void setHandler(FileHandler handler) {
        this.handler = handler;
    }


}
